001 /*
002 * Copyright 2005 Stephen J. McConnell.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
013 * implied.
014 *
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package net.dpml.component;
020
021 import java.util.EventObject;
022
023 /**
024 * Event triggered as a result of a model change.
025 *
026 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
027 * @version 1.0.0
028 */
029 public class ModelEvent extends EventObject
030 {
031 /**
032 * Serial version identifier.
033 */
034 static final long serialVersionUID = 1L;
035
036 private final String m_feature;
037 private final Object m_from;
038 private final Object m_to;
039
040 /**
041 * Construct a new <code>ModelEvent</code>.
042 *
043 * @param source the source component model
044 * @param feature the name of the model feature
045 * @param from the original value
046 * @param to the new value
047 */
048 public ModelEvent( final Model source, String feature, Object from, Object to )
049 {
050 super( source );
051
052 m_feature = feature;
053 m_from = from;
054 m_to = to;
055 }
056
057 /**
058 * Return the feature name.
059 * @return the name of the modified feature
060 */
061 public String getFeature()
062 {
063 return m_feature;
064 }
065
066 /**
067 * Return the old value.
068 * @return the original value
069 */
070 public Object getOldValue()
071 {
072 return m_from;
073 }
074
075 /**
076 * Return the new value.
077 * @return the new current value
078 */
079 public Object getNewValue()
080 {
081 return m_to;
082 }
083
084 /**
085 * Return the component model that initiating the event.
086 * @return the source model
087 */
088 public Model getSourceModel()
089 {
090 return (Model) super.getSource();
091 }
092 }
093